<template>
	<u-popup :show.sync="showProjectPopup" :round="10" mode="bottom" @close="close">
		<view class="popup_content">
			<view class="top_box">
				<view class="btn">
					选择项目
				</view>
				<view class="ipt_box">
					<u-icon name="search" color="#c0c0c0" size="28"></u-icon>
					<input v-model="project_name" @input="searchProject()" placeholder="关键字查找项目" type="text" />
				</view>
				<view @click="close()" class="text_box">
					关闭
				</view>
			</view>
			<view class="empty_box" v-if="projectList.length == 0">
				<u-empty text="暂无项目"></u-empty>
			</view>
			<!-- 仓库列表 -->
			<view v-else class="stashList_box">
				<view class="stashItem_box" v-for="(item,index) in projectList" :key="item.project_id">
					<view class="left">
						<u-icon name="list" color="#1296db" size="40"></u-icon>
						<text>{{item.project_name}}</text>
					</view>
					<view @click="selectProject(item)" class="right">
						选择
					</view>
				</view>
			</view>
		</view>
	</u-popup>
</template>
<script>
	import {
		getProjectListApi
	} from '@/api/receiveAndBorrow.js'
	export default {
		data() {
			return {
				projectList: [],
				project_name: '',
				timer: ''
			}
		},
		props: {
			showProjectPopup: {
				type: Boolean,
				default: false
			}
		},
		mounted() {
			this.getProjectList()
		},
		methods: {

			close() {
				this.$emit('update:showProjectPopup', false)
				this.project_name = ''
				this.getProjectList()
			},
			//获取项目
			async getProjectList() {
				const {
					data: {
						data: {
							list
						}
					}
				} = await getProjectListApi({
					project_name: this.project_name,
					page: 1,
					pageSize: 100
				})
				this.projectList = list
			},
			//选择单位
			selectProject(item) {
				this.$parent.formData.project = item.project_name
				this.close()
			},
			//搜索单位
			searchProject() {
				clearTimeout(this.timer)
				this.timer = setTimeout(() => {
					this.getProjectList()
				}, 500)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.popup_content {
		// height: 80vh;

		.top_box {
			display: flex;
			justify-content: space-between;
			font-size: 26rpx;
			padding: 20rpx;

			.btn {
				width: 120rpx;
				height: 70rpx;
				font-weight: 700;
				color: #000;
				text-align: center;
				line-height: 70rpx;


			}

			.ipt_box {
				display: flex;
				align-items: center;
				width: 480rpx;
				height: 70rpx;
				padding: 0 20rpx;
				background-color: #f2f2f2;
				border-radius: 35rpx;
				box-sizing: border-box;

				input {
					margin-left: 20rpx;
				}
			}

			.text_box {
				color: #60aeff;
				line-height: 70rpx;
			}
		}

		.stashList_box {
			height: 1000rpx;
			overflow: auto;
		}

		.stashItem_box {
			border-bottom: 1px solid #f2f2f2;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;

			.left {
				display: flex;
				align-items: center;
				font-weight: 700;

				text {
					margin-left: 20rpx;
				}
			}

			.right {
				width: 180rpx;
				height: 60rpx;
				background-color: #39cccc;
				color: #fff;
				text-align: center;
				line-height: 60rpx;
				border-radius: 35rpx;
			}
		}
	}

	.empty_box {
		padding-top: 200rpx;
		height: 1000rpx;
		box-sizing: border-box;
	}
</style>